VBScript → Lua
This function calls (launches) a given URL (http request) and returns True if the request returns without error.
Please see the Introduction chapter for some usage instructions.
'-------------------------------------------------------------------
' LaunchHTTPRequestEx
'
' Launches given URL by using the Swyx Server build-in PBXScript.WebRequest
'
' Parameter:
' sURL complete url
'
' return value:
' boolean True - request returned 200
' False - request returned anything else
'--------------------------------------------------------------------
Function LaunchHTTPRequestEx(sURL)
PBXScript.OutputTrace "------> LaunchHTTPRequestEx ( sURL = '" & sURL & "' )"
On Error Resume Next
Dim bReturn
bReturn = False
Dim oWebRequest, respCode
Set oWebRequest = PBXScript.WebRequest
oWebRequest.HttpVerb = HttpVerbGet
oWebRequest.URL = sURL
oWebRequest.AddHeader "Content-Type:application/text"
Dim vBefore, vAfter, nDuration
vBefore = Now
respCode = oWebRequest.Execute
vAfter = Now
nDuration = DateDiff("s", vBefore, vAfter)
PBXScript.OutputTrace "HTTP Request returned after " & nDuration & " seconds"
PBXScript.OutputTrace "Response Code = " & respCode
'PBXScript.OutputTrace "Response Body = " & oWebRequest.ResponseBody
bReturn = (respCode = 200)
LaunchHTTPRequestEx = bReturn
PBXScript.OutputTrace "bReturn = " & bReturn
PBXScript.OutputTrace "<------ LaunchHTTPRequestEx"
End Function
This function makes use of the Server Script API object PBXScript.WebRequest to perform the web reaquest and the function PBXScript.OutputTrace to write trace information into the SwyxServer trace file.
The PBXScript.WebRequest object was introducued with SwyxWare 12.40.
Another version of this function which makes use of the Windows "Msxml2.ServerXMLHTTP" object to perform the web request can be found in the LaunchHTTPRequest function.
By Tom Wellige
